/*
	Pulsar engine. Core.
	Debug functions and asserts.

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

#include <pulsar/pulsar.h>

namespace pl
{

} // namespace pl

/*
	Pass PL_TRACE event into the OS specific core
*/
void pl::_callOnTrace(const pl_char* file, pl_uint32 line, const pl_char* msg)
{
	if (pl::AppBase::appBase != NULL)
	{
		pl::AppBase::appBase->_onTrace(file, line, msg);
	}
	return;
}

/**
	Pass PL_ASSERTE/PL_ASSERTW event into the subscribers
*/
pl::HandleResult pl::_callOnAssert(const pl_char* file, pl_uint32 line, const pl_char* func, const pl_char* cond, const pl_char* msg, pl::AssertType type)
{
	// Check IAppDebug subscribers
	pl::HandleResult rc = IAppDebug::callOnAssert(file, line, func, cond, msg, type);
	if (rc != HANDLE_RESULT_NEXT)
	{
		return rc;
	}

	// Call standard app processing
	if (pl::AppBase::appBase != NULL)
	{
		return pl::AppBase::appBase->_onAssert(file, line, func, cond, msg, type);
	}
	// Always break to debugger
	return HANDLE_RESULT_DEBUG;
}

/**
	Pass memory error event into the subscribers
*/
pl::HandleResult pl::_callOnMemErr(const pl_char* file, pl_uint32 line, const pl_char* func, void* p, pl_int64 size, pl::MemoryError idEvent)
{
	// Check IAppDebug subscribers
	pl::HandleResult  rc = IAppDebug::callOnMemErr(file, line, func, p, size, idEvent);
	if (rc != HANDLE_RESULT_NEXT)
	{
		return rc;
	}

	// Call standard app processing
	if (pl::AppBase::appBase != NULL)
	{
		return pl::AppBase::appBase->_onMemErr(file, line, func, p, size, idEvent);
	}
	// Always break to debugger
	return HANDLE_RESULT_DEBUG;
}

//
// End of file 'pulsar_debugfunc.cpp'
//
